#include<bits/stdc++.h>
using namespace std;
const int ND=20;
int n,nD=0,d[ND],ok[ND][2],f[ND][2];
int F(int p,bool limit){
    if(p==0) return 1;
    if(ok[p][limit]) return f[p][limit];
    ok[p][limit]=1;
    for(int i=0;i<=(limit?d[p]:9);i++){
        if(i==4) continue;
        f[p][limit]+=F(p-1,limit&&i==d[p]);
    }
    return f[p][limit];
}
int main(){
    //freopen("four.in","r",stdin);
    //freopen("four.out","w",stdout);
    cin>>n;
    do{
        d[++nD]=n%10;
        n/=10;
    }while(n);
    cout<<F(nD,1)-1<<endl;
    return 0;
}